#line 1 "C:/Documents and Settings/Administrator/My Documents/TFC/trunk/monitor.c"
#line 1 "c:/documents and settings/administrator/my documents/tfc/trunk/monitor.h"
#line 1 "c:/documents and settings/administrator/my documents/tfc/trunk/spi.h"
#line 14 "c:/documents and settings/administrator/my documents/tfc/trunk/spi.h"
void spiInit();
char spiReadWait();
int spiRead(char *pSpiData);
void spiWrite(char spiData);
#line 69 "c:/documents and settings/administrator/my documents/tfc/trunk/monitor.h"
enum vResponse {

 Resp_Prompt_OK,
 Resp_Prompt_ND,
 Resp_Prompt_UE,
 Resp_Prompt_LE,
 Resp_Prompt_CF,
 Resp_Prompt_BC,
 Resp_Prompt_DF,
 Resp_Prompt_FI,
 Resp_Prompt_RO,
 Resp_Prompt_FO,
 Resp_Prompt_NE,
 Resp_Prompt_FN,
 Resp_Prompt_End,

 Resp_Message_NU,
 Resp_Message_DD1,
 Resp_Message_DD2,
 Resp_Message_DR1,
 Resp_Message_DR2,
 Resp_Message_Splash,
 Resp_None = 0xff
};

void monSendByte(char monData);
void monCmdSend(char monCmd);
void monCmdSendByteParam(char monCmd, unsigned char monParam);
void monCmdSendParam(char monCmd, unsigned char monCount, unsigned char *pmonParam);
enum vResponse monResponse();
enum vResponse monPrompt();
#line 11 "C:/Documents and Settings/Administrator/My Documents/TFC/trunk/monitor.c"
char pResponse[] = {

 Resp_Prompt_OK, 2, '>',0x0d,
 Resp_Prompt_UE, 2, 'E',0x0d,


 Resp_Prompt_ND, 3, 'N','D',0x0d,


 Resp_Prompt_DF, 3, 'D','F',0x0d,
 Resp_Prompt_FI, 3, 'F','I',0x0d,
 Resp_Prompt_RO, 3, 'R','O',0x0d,
 Resp_Prompt_FO, 3, 'F','O',0x0d,




 Resp_Message_DD1, 4, 'D','D','1',0x0d,

 Resp_Message_DR1, 4, 'D','R','1',0x0d,


};
#line 47 "C:/Documents and Settings/Administrator/My Documents/TFC/trunk/monitor.c"
void monSendByte(char monData)
{
  spiWrite (monData);
}








void monCmdSend(char monCmd)
{
 if (monCmd !=  0x0d )
 {
  spiWrite (monCmd);
 }
  spiWrite (0x0d);
}










void monCmdSendByteParam(char monCmd, unsigned char monParam)
{
  spiWrite (monCmd);
  spiWrite (' ');
  spiWrite (monParam);
  spiWrite (0x0d);
}










void monCmdSendParam(char monCmd, unsigned char monCount, unsigned char *pmonParam)
{
  spiWrite (monCmd);
 if (monCount--)
 {
  spiWrite (' ');
  spiWrite (*pmonParam++);
 while (monCount--)
 {
  spiWrite (*pmonParam++);
 }
 }
  spiWrite (0x0d);
}










enum vResponse monResponse() {

enum vResponse tpResp, tpThis;
unsigned char romBufOffset;
char cBuf[ 4 ];
unsigned char bufCnt, romCnt;
char data_in;
unsigned int tpBuf;


bufCnt = 0;
tpResp = Resp_None;



if ( spiRead (&data_in) !=  1 )
{
 for (bufCnt = 0; bufCnt <  4 ; bufCnt++)
 {
 romBufOffset = 0;

 cBuf[bufCnt] = data_in;

 while (tpResp == Resp_None)
 {
 tpThis = pResponse[romBufOffset++];
 romCnt = pResponse[romBufOffset++];
 if (romCnt == 0)
 {
 break;
 }
 if (romCnt == bufCnt + 1)
 {
 unsigned char j;
 tpResp = tpThis;
 for (j = 0; j < bufCnt; j++)
 {
 romCnt--;
 tpBuf = pResponse[romBufOffset++];
 if (tpBuf != cBuf[j])
 {
 tpResp = Resp_None;
 break;
 }
 }
 }
 else if (romCnt > bufCnt)
 {
 break;
 }
 romBufOffset += romCnt;
 }

 if (data_in == 0x0d)
 break;

 if (tpResp != Resp_None)
 break;


 data_in =  spiReadWait ();
 tpResp = Resp_None;
 }

 if (bufCnt ==  4 )
 {

 while (data_in != 0x0d)
 {
 data_in =  spiReadWait ();
 }
 }
}

return tpResp;
}









enum vResponse monPrompt()
{
 enum vResponse tpResp;

 do
 {
 tpResp = monResponse();
 } while (tpResp > Resp_Prompt_End);

 return tpResp;
}
